function zb(tbl){
	if(user()==null){
		return ">>:login?goto=zb/"+tbl.id
	}
	var zb= $fetch("zb",Cnd.where("id","=",tbl.id))
	var video=$fetch("video",Cnd.where("id","=",zb.vid))
	if(video!=null){
		var playinfo=foJson(video.PlayInfo)
		zb.put("playinfo",playinfo);
	}
	
	var num=parseInt(addnum(tbl).num);
    var end_time=zb.end_time;
    var lubo=0;
    if(end_time.getTime()<new java.util.Date().getTime()){
  	  lubo=1;
    }
    attr("lubo",lubo);
    zb.put("user",dao.fetch("users",Cnd.where("id","=",zb.user_id)))
    zb.put("teacher",dao.fetch("teacher",Cnd.where("name","=",zb.teacher)))
    zb.put("num",num)
    var user_list=cache.get("wsroom"+zb.id);
    if(user_list==null){
    	user_list=new java.util.HashSet();
    	user_list.add(user())
    }else{
    	user_list.add(user())
    }
    user_list=removalDuplicate(user_list,"id");
    cache.put("wsroom"+zb.id,user_list);
    return zb;
}


function websocket(tbl){
	var webSocketService=ioc.get("webSocketService",com.jse.service.WebSocketService.class)
	webSocketService.say("wsroom:"+tbl.room,tbl);
}

function danmu(tbl){
	var list=$app("zb"+tbl.id)
	$app("zb"+tbl.id,null)
	return list;
}
//发送的弹幕
function danmu1(tbl){
	//print(tbl)
	$app("zb"+tbl.id,tbl)
	//print($app("zb"+tbl.id))
}
function addnum(tbl){
	var num=tbl.num;
	try {
		num=$app("zbnum_"+tbl.id)
		num+=1;//Math.ceil(Math.random()*50);
	} catch (e) {
		num=1;
	}
	$app("zbnum_"+tbl.id,num)
	var uus=$sql("SELECT * FROM u WHERE id >= ((SELECT MAX(id) FROM u)-(SELECT MIN(id) FROM u)) * RAND() + (SELECT MIN(id) FROM u)  LIMIT 1")
	var uu=uus.get(0);
	uu.put("num",num)
	return uu;
}

function addzbnum(tbl){
	$app("zbnum_"+tbl.id,parseInt(tbl.num))
	return tbl.num;
}
//set 去除重复
function removalDuplicate(set,id) {
    var map = new NutMap();
    var tempSet = new java.util.HashSet();
    set.forEach(function(p){
        if(map.get(p.get(id)+"") == null ) {
            map.put(p.get(id)+"", p);                
        } else {
            tempSet.add(p);
        }
    })
    set.removeAll(tempSet);
    return set;
}